package ReviewStack;

import java.util.Arrays;

public class Stackself {
        public int[] array1;
        public int usedSize=0;
        public Stackself(){
            this.array1=new int[10];
        }

        //入栈
        public void push(int date){
            if(isFull()){
                this.array1= Arrays.copyOf(array1,2*array1.length);
            }
            array1[usedSize++]=date;
        }
        public boolean isFull(){
            return usedSize==array1.length;
        }
        //出栈
        public int pop(){
            if(isEmpty()){
                throw new RuntimeException("表为空！！！");
            }
            int count=array1[usedSize-1];
            usedSize--;
            return count;
        }
        public boolean isEmpty(){
            return usedSize==0;
        }
        //获取元素
        public int peek(){
            if(isEmpty()){
                throw new RuntimeException("栈空");
            }
            return array1[usedSize-1];
        }
        public void display(Stackself stack){
            if(isEmpty()){
                throw new RuntimeException("栈空！！！");
            }
            int len=usedSize;
            for(int i=0;i<len;i++){
                System.out.print(stack.pop()+" ");
            }
        }
    }
